//package com.example.springbootlearn.boot;
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.context.annotation.ComponentScan;
//import org.springframework.core.type.StandardAnnotationMetadata;
//import org.springframework.util.ClassUtils;
//import org.springframework.util.CollectionUtils;
//import org.springframework.util.ObjectUtils;
//import org.springframework.util.ReflectionUtils;
//
//import java.lang.annotation.Annotation;
//import java.lang.annotation.Target;
//import java.lang.reflect.AnnotatedElement;
//import java.util.*;
//import java.util.stream.Collectors;
//import java.util.stream.Stream;
//
///**
// * @author caiji Mr. Li
// * @date 2019/11/14 10:31
// */
//@Slf4j
//@TransactionalService(name = "test")
//public class TransactionalServiceBootStrap {
//
//    public static void main(String[] args) {
//        //第一种写法
////        AnnotatedElement annotatedElement = TestTransactionalService.class;
////        TransactionalService transactionalService = annotatedElement.getAnnotation(TransactionalService.class);
////
////        Set<Annotation> metaAnnotations = getAllMetaAnnotations(transactionalService);
////
////        metaAnnotations.forEach(TransactionalServiceBootStrap::printAnnotationAttribute);
//
//        //第二种写法
//        StandardAnnotationMetadata annotationMetadata = new StandardAnnotationMetadata(TransactionalServiceBootStrap.class);
//        // 获取所有的元注解类型（全类名）集合
//        Set<String> metaAnnotationTypes = annotationMetadata.getAnnotationTypes().stream()
//                .map(annotationMetadata::getMetaAnnotationTypes)
//                .collect(LinkedHashSet::new, Set::addAll, Set::addAll);
//
//        metaAnnotationTypes.forEach(metaAnnotation -> {
//            Map<String, Object> annotationAttributes = annotationMetadata.getAnnotationAttributes(metaAnnotation);
//            if (!CollectionUtils.isEmpty(annotationAttributes)) {
//                annotationAttributes.forEach((name,value)->{
//                    System.out.printf("注解 @%s 属性 %s = %s \n", ClassUtils.getShortName(metaAnnotation),name,value);
//                });
//            }
//        });
//    }
//
//
//    private static Set<Annotation> getAllMetaAnnotations(Annotation annotation) {
//        Annotation[] metaAnnotations = annotation.annotationType().getAnnotations();
//        if (ObjectUtils.isEmpty(metaAnnotations)) {
//            return Collections.EMPTY_SET;
//        }
//        Set<Annotation> metaAnnotationSet = Stream.of(metaAnnotations)
//                .filter(metaAnnotation -> !Target.class.getPackage().equals(metaAnnotation.annotationType().getPackage()))
//                .collect(Collectors.toSet());
//
//        Set<Annotation> collect = metaAnnotationSet.stream().map(TransactionalServiceBootStrap::getAllMetaAnnotations)
//                .collect(HashSet::new, Set::addAll, Set::addAll);
//        metaAnnotationSet.addAll(collect);
//        return metaAnnotationSet;
//    }
//
//    private static void printAnnotationAttribute(Annotation annotation) {
//        Class<? extends Annotation> annotationType = annotation.annotationType();
//        ReflectionUtils.doWithMethods(annotationType,
//                method -> log.info("@{}.{}()= {}\n", annotationType.getName(), method.getName(), ReflectionUtils.invokeMethod(method, annotation)),
//                method -> !method.getDeclaringClass().equals(Annotation.class));
//    }
//}
